package com.javayh.dao;

import com.javayh.bean.UserAndRoleVo;
import com.javayh.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Dylan Yang
 * @Title: UserDao
 * @ProjectName lucky
 * @Description: TODO
 * @date 2018/10/215:51
 */
@Mapper
@Component
public interface UserDao {

    /**
      * 查询所有用户
      * @author Dylan Yang
      */
    @Select(value = "SELECT * FROM u_user")
    List<User> queryUsers();

    /**
      * 查询用户对应的角色
      * @author Dylan Yang
      */
    @Select(value = "SELECT " +
                        "user.id,user.nickname,user.email,user.status,role.name,role.type " +
                        "FROM u_user AS user " +
                        "LEFT JOIN u_user_role AS urole ON urole.uid = user.id " +
                        "LEFT JOIN u_role AS role ON urole.rid = role.id")
    List<UserAndRoleVo> queryUserAndRoleAll();

    /**
      * 根据明细进行查询
      * @author Dylan Yang
      */
    @Select(value = "SELECT * FROM u_user where nickname = #{nickName}")
    User findByName(@Param("nickName")String nickName);
}

